﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HR60_PanelSoft.NetWork.Base
{
    class PackageAck
    {
        public byte length = 6;
        public byte c;
        public byte dataType;
        public byte panelNo;
        public byte subDataSN;
        public byte ans;
        public byte cs;



        public static bool parsePackage(byte[] data)
        {
            if (data.Length != 7)
                return false;

            PackageAck pa = genPackageAck(data);
            if (pa.ans == 0)
            {
                return true;
            }
            else
            {
                return false;
            }

        }
        public static PackageAck genPackageAck(byte[] data)
        {
            PackageAck pa = new PackageAck();
            pa.length = data[0];
            pa.c = data[1];
            pa.dataType = data[2];
            pa.panelNo = data[3];
            pa.subDataSN = data[4];
            pa.ans = data[5];
            pa.cs = data[6];


            return pa;
        }

        private static byte genCs(PackageAck package)
        {
            int rt = 0;

            byte length = package.length;
            byte c = package.c;
            byte dataType = package.dataType;
            byte panelNo = package.panelNo;
            byte subDataSN = package.subDataSN;
            byte ans = package.ans;

            rt = rt + length;
            rt = rt + c;
            rt = rt + dataType;
            rt = rt + panelNo;
            rt = rt + subDataSN;
            rt = rt + ans;

            return (byte)(rt % 256);


        }

    }
}
